package com.cheney.diandireader.server.service;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.cheney.diandireader.server.dao.BaseDAO;
import com.cheney.diandireader.server.domain.AttachFile;

@Service
public class FileManageService implements IService{
	
	private BaseDAO<AttachFile> baseDAO;
	
	@Autowired
	public void setSessionFactory(@Qualifier("sessionFactory")SessionFactory sessionFactory){
		baseDAO = new BaseDAO<AttachFile>(sessionFactory,AttachFile.class);
	}
	
	//save
	public void save(AttachFile attachFile){
		baseDAO.save(attachFile);
	}
	
	//findAll
	public List<AttachFile> list(){
		return baseDAO.findAll();
	}
	
	//findBySuperId
	public List<AttachFile> listBySuperId(String id){
		return baseDAO.findByProperty("superAttachFile.id",id);
	}
	
	public List<AttachFile> findBySQL(String id){
		String hql = "from AttachFile att where att.superAttachFile.id = ?";
		return baseDAO.find(hql, id);
	}
	
	//delete
	public void delete(AttachFile attachFile){
		if(attachFile!=null)
		baseDAO.delete(attachFile);
	}
	
	//update
	public void update(AttachFile attachFile){
		if(attachFile!=null)
		baseDAO.update(attachFile);
	}
}
